package com.mango.ch04;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class SecondarySortGroupComparator extends WritableComparator {

	public SecondarySortGroupComparator() {
		/**
		 * 一定要写 super(CompositeKey.class, true); 否则报下面的错 Error:
		 * java.lang.NullPointerException at
		 * org.apache.hadoop.io.WritableComparator.compare(WritableComparator.java:157)
		 * 
		 */
		super(MyPair.class, true);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public int compare(WritableComparable a, WritableComparable b) {
		// TODO Auto-generated method stub
		MyPair m1 = (MyPair) a;
		MyPair m2 = (MyPair) b;
		return m1.getFirst().compareTo(m2.getFirst());
	}

}
